import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from Base.BasePage import BasePage


class Managemnet(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        self.guanli = (By.XPATH, '//html/body/div[1]/div[2]/ul/li[2]/a')
        self.all_brw = (By.XPATH, '//*[@id="sidebar"]/ul/li[1]/a/span')
        self.brw_aplay = (By.XPATH, '//*[@id="sidebar"]/ul/li[1]/ul/li[2]/a')
        self.ifram = (By.ID, 'iframe_box')
        self.name = (By.NAME, 'name')
        self.phone = (By.NAME, 'phone')
        self.email = (By.NAME, 'email')
        self.start_time = (By.NAME, 'start_time')
        self.end_time = (By.NAME, 'end_time')
        # 状态
        self.status = (By.NAME, 'status')
        self.search = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[7]/input')
    #     选择
        self.select = (By.XPATH, ' /html/body/div[2]/div[3]/table/tbody/tr[1]')

    #     /html/body/div[2]/div[3]/table/tbody/tr[2]
    #     审核
        self.review = (By.XPATH, '/html/body/div[2]/div[2]/ul/li[1]/a')
    #     ifram2
        self.ifram2 = (By.XPATH, '//*[@id="xubox_iframe1"]')
    #     通过
        self.pass_review = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[1]/td[2]/div/label[1]/input')
    #     保存
        self.save = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[2]/td[2]/input[1]')

    def management_search_name(self, name):
        self.click_element(self.guanli)
        self.click_element(self.all_brw)
        time.sleep(1)
        self.click_element(self.brw_aplay)
        self.switch_frame(self.ifram)
        self.base_clear_input(self.name, name)
        select = Select(self.get_element(self.status))
        select.select_by_visible_text('待审核')
        time.sleep(1)
        self.click_element(self.search)
        time.sleep(1)
        self.click_element(self.select)
        self.click_element(self.review)
        self.switch_frame(self.ifram2)
        self.click_element(self.pass_review)
        self.click_element(self.save)
        pass
